<form class="layui-form seller-form"  action="" >
    <div class="layui-form-item">
        <div class="layui-inline" style="display:none;">
            <label class="layui-form-label">账号：</label>
            <div class="layui-input-inline">
                <input type="text" name="username" lay-verify="title" style="width:100px;" placeholder="请输入账号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">手机号码：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="mobile" lay-verify="title" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">性别：</label>
            <div class="layui-input-inline seller-inline-2" >
                <select name="sex" lay-verify="">
                    <option value=""></option>
                    <option value="1">男</option>
                    <option value="2">女</option>
                    <option value="3">其他</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">生日：</label>
            <div class="layui-input-inline seller-inline-2">
                <input type="text" name="birthday" lay-verify="title" placeholder="生日日期" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">昵称：</label>
            <div class="layui-input-inline seller-inline-2">
                <input type="text" name="nickname" lay-verify="title" placeholder="用户昵称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态：</label>
            <div class="layui-input-inline seller-inline-3">
                <select name="status" lay-verify="">
                    <option value=""></option>
                    <option value="1">正常</option>
                    <option value="2">停用</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
	        <div class="layui-input-block">
	            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>筛选</button>
	        </div>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="userTable" lay-filter="test"></table>
</div>

<script>
    var window, table;
    layui.use(['form', 'layedit', 'laydate', 'table', 'layer'], function(){
        table = layui.table.render({
            elem: '#userTable',
            height: 'full-330',
            cellMinWidth: '80',
            page: 'true',
            limit:'20',
            url: "{:url('user/point')}?_ajax=1",
            id:'userTable',
            response: {
                statusName: 'status',
                statusCode: 1
            },
            cols: [[
                {type:'numbers'},
                {field:'mobile', width:160, title:'手机号码'},
                {field:'sex', width:80, minWidth:50, title:'性别'},
                {field:'birthday', width:200, title:'生日'},
                {field:'avatar', title:'头像',
                    templet: function(d){
                        if (d.avatar) {
                            return '<a href="javascript:void(0);" onclick=viewImage("'+d.avatar+'")><image style="max-width:30px;max-height:30px;" src="'+d.avatar+'"/></a>';
                        }else{
                            return '<a href="javascript:void(0);" onclick=viewImage("<?php echo config('jshop.default_image'); ?>")><image style="max-width:30px;max-height:30px;" src="<?php echo config('jshop.default_image');?>"/></a>';
                        }
                    }
                },
                {field:'nickname', title:'昵称'},
                {field:'point', title:'积分'},
                {field:'status', title:'状态'},
                {field:'operating',width:195,title:'操作', align: 'center',templet:function(data){
                        var html = '';
                        html += '<span class="layui-btn layui-btn-xs show-log" data-user_id="'+data.user_id+'" data-seller_id="'+data.seller_id+'">查看积分记录</span>';
                        html += '<a class="layui-btn layui-btn-xs edit-point" data-user_id="'+data.user_id+'" data-seller_id="'+data.seller_id+'">编辑积分</a>';
                        return html;
                    }, fixed: 'right'}
            ]]
        });
        layui.form.on('submit(*)', function(data){
            layui.table.reload('userTable', {
                where: data.field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //查看积分记录
        $(document).on('click', '.show-log', function(){
            var seller_id = $(this).attr('data-seller_id');
            var user_id = $(this).attr('data-user_id');
            JsPost("{:url('User/pointLog')}", {seller_id: seller_id, user_id: user_id}, function(e){
                window.box = layer.open({
                    type: 1,
                    content: e,
                    area: ['700px', '450px'],
                    title:'积分记录'
                });
            });
        });

        //编辑积分
        $(document).on('click', '.edit-point', function(){
            var seller_id = $(this).attr('data-seller_id');
            var user_id = $(this).attr('data-user_id');
            JsPost("{:url('User/editPoint')}", {seller_id: seller_id, user_id: user_id}, function(e){
                window.box = layer.open({
                    type: 1,
                    content: e,
                    area: ['480px', '300px'],
                    title:'积分编辑'
                });
            });
        });

        //编辑保存积分
        $(document).on('click', '.edit-point-save', function () {
            let user_id = $("#user_id").val();
            let seller_id = $("#seller_id").val();
            let point = $("#point").val();
            let memo = $("#memo").val();
            let point_old = $("#point_old").val();
            if(point_old*1+point*1 < 0) {
                layer.msg('扣除积分不能大于用余额积分');
                return false;
            } else {
                let data = {
                    user_id: user_id,
                    seller_id: seller_id,
                    point: point,
                    memo: memo,
                    flag: 'true'
                };
                JsPost("{:url('User/editPoint')}", data, function(e){
                    if(e.status) {
                        layer.closeAll();
                        table.reload();
                    } else {
                        layer.msg(e.msg);
                    }
                });
            }
        });
    });
</script>
